package com.bblocks.standard.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bblocks.common.Constant;
import com.bblocks.standard.dao.SysParamDao;
import com.bblocks.standard.entity.SysParam;
import com.bblocks.standard.service.SysParamService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * 系统配置(SysParam)表服务实现类
 *
 * @author makejava
 * @since 2021-10-29 13:57:47
 */
@Slf4j
@Service("sysParamService")
@CacheConfig(cacheNames = "SysParam2")
public class SysParamServiceImpl extends ServiceImpl<SysParamDao, SysParam> implements SysParamService {
    @Lazy
    @Autowired
    SysParamService sysParamService;

    @Cacheable(key = "'&name='+#p0" )
    public SysParam getByName(String name){
        LambdaQueryWrapper<SysParam> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(SysParam::getName, name);

        return this.getOne(wrapper);
    }


    public String getByNameValue(String name,String defaultValue){
        SysParam param=  sysParamService.getByName(name);
        if(param == null)
            return defaultValue;
        else
            return param.getValue();
    }

    public String getDefaultCityCode(){
        SysParam param =  sysParamService.getByName(Constant.YZ_SYS_DEFAUL_CITY_CODE_KEY);
        if(param == null)
            return "320100";
        else
            return param.getValue();
    }



    public Integer getAccByName(String name,Integer defaultValue){
        SysParam param =  sysParamService.getByName(name);
        if(param == null)
            return defaultValue;
        else
            return Integer.parseInt(param.getValue()) ;

    }
}

